package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SalaryPlanFormulaAddDTO;
import org.jsola.hr.dto.SalaryPlanFormulaUpdateDTO;
import org.jsola.hr.entity.SalaryPlanFormulaDO;
import org.jsola.hr.query.SalaryPlanFormulaQuery;
import org.jsola.hr.service.ISalaryPlanFormulaService;
import org.jsola.hr.vo.SalaryPlanFormulaVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class SalaryPlanFormulaTestHelper extends BaseTestHelper {

    @Autowired
    private ISalaryPlanFormulaService salaryPlanFormulaService;

    /**
     * 生成add测试数据
     * @return SalaryPlanFormulaAddDTO
     */
    public SalaryPlanFormulaAddDTO getSalaryPlanFormulaAddDTO(){
        SalaryPlanFormulaAddDTO salaryPlanFormulaAddDTO = new SalaryPlanFormulaAddDTO();
        salaryPlanFormulaAddDTO.setSalaryPlanId(getRandomValue("varchar",32));
        salaryPlanFormulaAddDTO.setFormula(getRandomValue("varchar",255));
        salaryPlanFormulaAddDTO.setConditionRelation(SafeKit.getInteger(getRandomValue("tinyint",4)));
        salaryPlanFormulaAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",11)));
        salaryPlanFormulaAddDTO.setCompanyId(getRandomValue("varchar",32));
        return salaryPlanFormulaAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SalaryPlanFormulaUpdateDTO
     */
    public SalaryPlanFormulaUpdateDTO getSalaryPlanFormulaUpdateDTO(SalaryPlanFormulaVO salaryPlanFormulaVO){
        return salaryPlanFormulaService.selectDOById(salaryPlanFormulaVO.getId(), SITE_ID).to(SalaryPlanFormulaUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SalaryPlanFormulaQuery
     */
    public SalaryPlanFormulaQuery getSalaryPlanFormulaQuery() {
        SalaryPlanFormulaQuery salaryPlanFormulaQuery = new SalaryPlanFormulaQuery();
        List<SalaryPlanFormulaDO> salaryPlanFormulaDOList = salaryPlanFormulaService.list(new SalaryPlanFormulaDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(salaryPlanFormulaDOList)) {
            SalaryPlanFormulaDO salaryPlanFormulaDO = salaryPlanFormulaDOList.get(0);
            salaryPlanFormulaQuery = salaryPlanFormulaDO.to(SalaryPlanFormulaQuery.class);
            if (salaryPlanFormulaDO.getGmtCreate() != null) {
                salaryPlanFormulaQuery.setGmtCreateStart(DateKit.getBeforeDay(salaryPlanFormulaDO.getGmtCreate(),-1));
                salaryPlanFormulaQuery.setGmtCreateEnd(DateKit.getBeforeDay(salaryPlanFormulaDO.getGmtCreate(),1));
            }
            if (salaryPlanFormulaDO.getGmtModified() != null) {
                salaryPlanFormulaQuery.setGmtModifiedStart(DateKit.getBeforeDay(salaryPlanFormulaDO.getGmtModified(),-1));
                salaryPlanFormulaQuery.setGmtModifiedEnd(DateKit.getBeforeDay(salaryPlanFormulaDO.getGmtModified(),1));
            }
        }
        return salaryPlanFormulaQuery;
    }

    /**
     * 保存示例
     * @return SalaryPlanFormulaVO
     */
    public SalaryPlanFormulaVO saveSalaryPlanFormulaExample(){
        SalaryPlanFormulaAddDTO addDTO = this.getSalaryPlanFormulaAddDTO();
        SalaryPlanFormulaVO salaryPlanFormulaVO = salaryPlanFormulaService.save(addDTO,buildTokenUser());
        return salaryPlanFormulaVO;
    }

    public List<SalaryPlanFormulaAddDTO> getSalaryPlanFormulaAddDTOList(){
        List list=new ArrayList();
        list.add(this.getSalaryPlanFormulaAddDTO());
        list.add(this.getSalaryPlanFormulaAddDTO());
        return list;
    }

}

